/* $Id: AdminNonClientCompanyReviewDelegateImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.delegate.provider;

import java.util.List;

import org.apache.commons.lang.WordUtils;

import ae.pcfc.etks.online.common.delegate.AdminNonClientCompanyReviewDelegate;
import ae.pcfc.etks.online.common.exception.AdminWorkflowException;
import ae.pcfc.etks.online.common.facade.AdminNonClientCompanyReviewFacade;
import ae.pcfc.etks.online.common.facade.UserFacade;
import ae.pcfc.etks.online.common.vo.AdminApprovalVO;
import ae.pcfc.etks.online.common.vo.NonClientCompanyVO;
import ae.pcfc.etks.online.common.vo.WorkFlowTaskInformationVO;
import ae.pcfc.etks.online.wf.ConstantsWF;
import ae.pcfc.etks.online.wf.Utils;
import ae.pcfc.etks.online.wf.service.client.NonClientWF;
import ae.pcfc.etks.online.wf.service.client.provider.NonClientCompanyWFImpl;
import ae.pcfc.etks.online.wf.service.client.vo.NonClientCompleteStepVO;
import ae.pcfc.etks.online.wf.service.client.vo.TaskInformationVO;

public class AdminNonClientCompanyReviewDelegateImpl  extends BaseDelegateImpl implements AdminNonClientCompanyReviewDelegate{
	
	/*
	 * Here we coordinate between the Facade service which handles DB entities
	 * and the WF both will be looked up with service locator normally we will
	 * have 1-1 relationship between the delegate and the facade and 1-1
	 * relationship between the delegate and the WF service which means for
	 * CompanyRegistrationDelegate there will be ClientRegistrationFacade &
	 * CompanyRegistrationWF validations that related to DB vs WF are maintained
	 * here ie user cannot issue a new request while he already have a request
	 * in the wf Exception are translated in to business exception
	 */
	public AdminNonClientCompanyReviewDelegateImpl(){
		
	}
	
	/**
	 * getNonClientCompanyByApplicationId
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.AdminNonClientCompanyReviewDelegate#getNonClientCompanyByApplicationId(java.lang.String)
	 * 
	 */
	public NonClientCompanyVO getNonClientCompanyByApplicationId(
			String applicationId) {
		return serviceLocator.getFacadeService(AdminNonClientCompanyReviewFacade.class).getNonClientCompanyByApplicationId(applicationId);	 
		 
	}

	
	/**
	 * reviewNonClientCompany
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.AdminNonClientCompanyReviewDelegate#reviewNonClientCompany(ae.pcfc.etks.online.common.vo.AdminApprovalVO, java.lang.String)
	 * 
	 */
	public void reviewNonClientCompany(AdminApprovalVO adminApprovalVO, String strUserName) 
	{		
		//serviceLocator.getFacadeService(AdminNonClientCompanyReviewFacade.class).reviewNonClientCompany(adminApprovalVO, strUserName);
		AdminNonClientCompanyReviewFacade adminNonClientCompanyReviewFacade = serviceLocator.getFacadeService(AdminNonClientCompanyReviewFacade.class);
		NonClientCompleteStepVO completeStepVO = adminNonClientCompanyReviewFacade.reviewNonClientCompany(adminApprovalVO, strUserName);
	    try{
			NonClientWF nonClientWF = serviceLocator.getWorkflowService(NonClientCompanyWFImpl.class);
			nonClientWF.completeNonClientWFStep(completeStepVO);
	    }catch(Throwable t){
	    	adminNonClientCompanyReviewFacade.undoReviewNonClientCompany(adminApprovalVO, completeStepVO.getgTKSID());
	    	throw new AdminWorkflowException(t);
	    }

	}
	
}
